
/*sessionStorage.setItem("userId","13485221331063032"); 
sessionStorage.setItem("name","苏慧");
sessionStorage.setItem("jobnumber","0");
sessionStorage.setItem("deptId","55088496");
*/

//sessionStorage.setItem("userId","193114475332300122"); 
//sessionStorage.setItem("name","任丽琴");
//sessionStorage.setItem("jobnumber","009028");
//sessionStorage.setItem("deptId","55088496");
//sessionStorage.setItem("mobile","18334724145");

//sessionStorage.setItem("userId","134916456822004904"); 
//sessionStorage.setItem("name","段俊杰");
//sessionStorage.setItem("jobnumber","009101");
//sessionStorage.setItem("deptId","55088496");


//sessionStorage.setItem("userId","1304442705697854");
var nowDate = getDay(0);
var thesum=0;    //待办事项返回数量
var resdata=[];  //待办事项返回数据
var sendData = {};  //待办事项
//sendData.planuserid =sessionStorage.getItem("userId");
sendData.flag=10;
sendData.flag1=12;
var daibannum = 0;
var pageType = GetQueryString('pageType')==null?"":GetQueryString('pageType');
if(pageType == ''){
	pageType = sessionStorage.getItem("pageType");
}
var corp = GetQueryString('corp')==null?"":GetQueryString('corp');
if(corp==''){
	corp = sessionStorage.getItem("corp");
}else{
	sessionStorage.setItem("corp",corp);
}


if(sessionStorage.getItem("name")){
	//alert(localStorage.getItem("name"));
//	setthenum();
	if(pageType == 'yingyun'){
		getYingyunUser();
	}
	onload();
}else{

	var _config ;
	$.ajax({
		type : "post",
		data:JSON.stringify({"pageUrl":location.href.replace(/\\&/g,'%26'),"corp":corp}),
		contentType: "application/json; charset=utf-8",
		async: false,
		url : "../../dingding/getconfig",
		dataType : "json",
		success : function(suc) {
			_config = suc.config;
		}
	}); 
//	dd.config({
//		agentId : _config.agentid,
//		corpId : _config.corpId,
//		timeStamp : _config.timeStamp,
//		nonceStr : _config.nonceStr,
//		signature : _config.signature,
//		jsApiList : [ 'runtime.info', 'biz.contact.choose',
//				'device.notification.confirm', 'device.notification.alert',
//				'device.notification.prompt', 'biz.ding.post',
//				'biz.util.openLink' ]
//	});
	dd.ready(function() {
		//channel runtime  requestOperateAuthCode requestAuthCode
	    dd.runtime.permission.requestAuthCode({
	        corpId: _config.corpId,
	        onSuccess: function(result) {
	        	getuserId(result);
	        },
	        onFail : function(err) {
	        	alert("错误"+JSON.stringify(err))
	        }
	 
	    });
	});
	function getuserId(result){
			    //$("body").text('https://oapi.dingtalk.com/user/getuserinfo?code=' + result.code + '&access_token='+ _config.token);
		$.ajax({
			url : '../../dingding/ddEasy',
			type : 'POST',
			data:JSON.stringify({"code":result.code,"token":_config.token}),
			contentType: "application/json; charset=utf-8",
			dataType : "json",
			success : function(suc) {
			    if(suc.status == '1002'){
			    	sessionStorage.setItem("userId",suc.userJson.userid);
			    	sessionStorage.setItem("name",suc.userJson.name);
			    	sessionStorage.setItem("jobnumber",suc.userJson.jobnumber);
			    	sessionStorage.setItem("deptId",suc.userJson.department);
			    	sessionStorage.setItem("mobile",suc.userJson.mobile);
//					setthenum();
					if(pageType == 'yingyun'){
						getYingyunUser();
					}
					onload();
			    	
			    }else{
			    	layer.alert(suc.msg);
			    }

			},
			error : function(xhr, errorType, error) {
					alert(errorType + ', ' + error);
				}
		});
	}
	dd.error(function(err) {
		alert('dd error: ' + JSON.stringify(err));
	});
}
//获得职位及子职位
function getYingyunUser(){
	$.ajax({
		type : "post",
		async: false,
		data: JSON.stringify({'jobnumber':sessionStorage.getItem('jobnumber')}),
		contentType:'application/json; charset=utf-8',
		url : "../../dingding/getYingyunUser",
		dataType : "json",
		success : function(suc) {
			sessionStorage.setItem("job",suc.data.job);
//			sessionStorage.setItem("pjob",suc.data.pjob);
//			sessionStorage.setItem("pjobnumber",suc.pjobnumber);
//			sessionStorage.setItem("cjob",suc.data.cjob);
//			job = suc.data.job;
//			cjob = suc.data.cjob;
//			onload();
		}
	}); 
}

function onload(){

	$('#name').text(sessionStorage.getItem("name"));
	if(pageType == 'yingyun'){
		$('.bigbox_button['+pageType+']').show();
		$('.bigbox_button[job="'+sessionStorage.getItem("job")+'"]').show();
	}else if(pageType == 'pandian'){
		$('.bigbox_button['+pageType+']').show();
		pandianZhong();
	}else if(pageType == 'daiban'){
		$('.bigbox_button['+pageType+']').show();
	}else{
		$('.bigbox_button:not([job])').show();
	}
	addClick();
	pandianDaihuifu();
	FankuiDaihuifu();
	pandianDaizongjie();
	FankuiDaixiugai();
	FankuiDaiwancheng();
	pandianDaishenpi();
}
function addClick(){
	$('.bb_img').on('click',function(){
		sessionStorage.setItem("pageType",pageType);
		window.location.href=$(this).attr('pageUrl');
	});
}
//查询盘点待总结信息
function pandianDaizongjie(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.zongjieuserjobnumber=sessionStorage.getItem("jobnumber");
	sendData.zongjieFlag=0;
	$.ajax({
		url: "../pandianevery/pandianDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#zongjieTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#zongjieTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询盘点待回复信息
function pandianDaihuifu(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
//	sendData.huifuuser=userId;
	sendData.huifuuserjobnumber=sessionStorage.getItem("jobnumber")
	sendData.huifuFlag=0;
//	sendData.zongjieFlag=1;
	$.ajax({
		url: "../pandianevery/pandianDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#dataTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#dataTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}

//查询盘点待回复信息
function FankuiDaihuifu(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.senduser=sessionStorage.getItem("userId");
	sendData.flag=0;
	sendData.shenpiFlag=0;
	$.ajax({
		url: "../pandianevery/FankuiDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询盘点待完成信息
function FankuiDaiwancheng(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.wanchenguser=sessionStorage.getItem("userId");
	sendData.flag=2;
	$.ajax({
		url: "../pandianevery/FankuiDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询盘点反馈待修改信息
function FankuiDaixiugai(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.wanchengUser=sessionStorage.getItem("userId");
//	sendData.flag=0;
	sendData.querenFlag=2;
	$.ajax({
		url: "../pandianevery/FankuiDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询盘点待审批信息
function pandianDaishenpi(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.querenUser=sessionStorage.getItem("userId");
	sendData.querenFlag=0;
	$.ajax({
		url: "../pandianevery/getPandianJiancha"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#zongjieTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#zongjieTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//查询待盘点数据
function pandianZhong(){
	var sendData = {};
	sendData.latitude='37.862444';
	sendData.longitude='112.546997';
	sendData.pandianDate= nowDate;
	sendData.flag = '1,10';
	sendData.nolimit = 'true';
//	sendData.notFlag=0;
	$.ajax({
		url: "../pandianevery/getShopWeizhi",
		type : 'POST',
		data: JSON.stringify(sendData),
		contentType: "application/json; charset=utf-8",
		dataType : "json",
		success : function(res) {
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//function setthenum(){
//	$.ajax({              //待办事项
//	url: "../../unite_platform/work_plan_info/getBody"
//	,type:'post'
//	,async: false
//	,contentType: "application/json; charset=utf-8"
//	,data:JSON.stringify(sendData) 
//	,dataType:'json'
//	,success: function(res){
//		console.log(res.data);
//		for(var p in res.data){//遍历json对象的每个key/value对,p为key
// 		    var  shuzu = res.data[p];
//				for(var p1 in shuzu){
//					var thelength = shuzu[p1].length;
//					var theshuzu = shuzu[p1];
//							for(var a1=0;a1<thelength;a1++){
//								resdata.push(theshuzu[a1]);
//							}
// 				}
//		}
//		thesum=resdata.length;
//		$('#add_number').html(thesum);
//	}
//	});
//}
